//
//  Collect.m
//  YiShangPin
//
//  Created by yishangpin2 on 15/3/12.
//  Copyright (c) 2015年 yishangpin2. All rights reserved.
//

#import "Collect.h"
#import "Waterfall.h"
#import "AppDelegate.h"

@interface Collect (){
    AppDelegate *delegate;
    float AllY;
    int WaterfallViewHeight;
    

}

@end

@implementation Collect

- (void)viewDidLoad {
    [super viewDidLoad];
    delegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    //瀑布流的起始位置
    WaterfallViewHeight = 0;
    
    [self Waterfall_Upload];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    self.navigationItem.title = @"Miscellaneous";
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - 瀑布流排布

//瀑布流排布商品信息
- (void)Waterfall_Upload{
    NSMutableArray *picmutArray = [NSMutableArray arrayWithObjects:@"fushi1.jpg",@"fushi2.jpg",@"fushi3.jpg",@"fushi4.jpg",@"fushi5.jpg",@"fushi6.jpg",@"fushi7.jpg",@"fushi8.jpg",@"fushi9.jpg",@"fushi10.jpg",@"fushi11.jpg",@"fushi12.jpg", nil];
    for (int i = 0; i<delegate.CollectArray.count; i++) {
        [picmutArray insertObject:[NSString stringWithFormat:@"fushi%d.jpg",([delegate.CollectArray[i] integerValue]-1000)] atIndex:i];
    }
    
    
    
    NSMutableArray *oldprice = [NSMutableArray arrayWithObjects:@"168",@"129",@"200",@"234",@"321",@"157",@"123",@"453",@"290",@"310", nil];
    NSMutableArray *newprice = [NSMutableArray arrayWithObjects:@"68",@"89",@"100",@"134",@"221",@"97",@"83",@"200",@"190",@"210", nil];
    
    
    
    //    UIImage *image = [UIImage imageNamed:picmutArray[4]];
    

    
    int y = 0, y1 = 1;
    
    for (int i = 0; i<delegate.CollectArray.count; i++) {
        
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Waterfall" owner:self options:nil];
        Waterfall *waterView = nib[0];
        
        waterView.tag = 1001+i;
        //        int Y = (y<y1)?y:y1;
        //判断是左边还是右边
        int Y;
        BOOL BOOLY;
        if (y<y1) {
            BOOLY = YES;
            Y = y;
        }
        else
        { BOOLY = NO;
            Y = y1;
        }
        int X = (y<y1)?0:self.view.frame.size.width/2;
        
        
        UIImage *image = [UIImage imageNamed:picmutArray[i]];
        //        [waterView ViewframSetX:0 SetY:0 Pic:image];
        [waterView ViewframSetX:X SetY:Y Pic:image delegateW:self.view.frame.size.width];
        [waterView SetOldPrice:[oldprice[i] floatValue] SetNewPrice:[newprice[i] floatValue]];
        
        if(BOOLY)
            y += waterView.viewY;
        else
            y1 += waterView.viewY;
        //        waterView.backgroundColor = [UIColor redColor];
        //        waterView.alpha = 0.5;
        [waterView.Collect setImage:[UIImage imageNamed:@"打钩.png"] forState:0];
        [waterView.Collect setTitle:@" Edit List" forState:0 ];
        [self.WaterfallView addSubview:waterView];
        [self.Scrollview addSubview:self.WaterfallView];
        
    }
    
    AllY = (y<y1)?y1:y;
    self.WaterfallView.frame = CGRectMake(0, WaterfallViewHeight, self.view.frame.size.width, AllY+56);
    self.Scrollview.contentSize = CGSizeMake(self.view.frame.size.width, AllY + WaterfallViewHeight);
    
    
}


@end
